<?php 
class Admin_Form_Product extends Zend_Form{
    
   public function init(){
        $this->setMethod("post");
		$this->setName("ProductForm");
        $this->setAttrib('autocomplete', 'off');	        	
        $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
        $this->setElementDecorators(array(
            array('ViewHelper'),
            array('Errors'),
            array('Description'),
            array('Label', array('separator'=>' ')),
            array('HtmlTag', array('tag' => 'li', 'class'=>'element-group')),
        ));
        $modelCat = new Vina_Model_Categories();
        $listAllCat = $modelCat->fetchListToArray("1=1");
        foreach($listAllCat as $vCat):
        $optionCat["{$vCat['id']}"] = $vCat['name'];
        endforeach;
    
        $optionCat[''] = "Chọn danh mục!";
        $category = new Zend_Form_Element_Select('category_id');
        $category->setLabel('Danh mục')
              ->setMultiOptions($optionCat);
        $category->setValue('');
        
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('Tên SP')
             ->setRequired(true)
             ->addValidator('NotEmpty',true,array('messages' => 'Không được chống!'));     
        $name->setAttrib('size', '70');
        
        $name_en = new Zend_Form_Element_Text('name_en');
        $name_en->setLabel('Tên SP Engish');     
        $name_en->setAttrib('size', '70');
        
        $name_chi = new Zend_Form_Element_Text('name_china');
        $name_chi->setLabel('Tên SP China');     
        $name_chi->setAttrib('size', '70');
		
	
        $image = new Zend_Form_Element_File('image');
        $image->setLabel('Hình ảnh')
              ->setDestination(APPLICATION_PATH ."/../public/upload")
              ->setRequired(true)
              //->setMaxFileSize(10240000) // limits the filesize on the client side
              ->setDescription('Nhấn vào nút browse để upload hình ảnh');
        $image->addValidator('Count', false, 1);                // ensure only 1 file
        $image->addValidator('Size', false, 10240000);            // limit to 10 meg
        $image->addValidator('Extension', false, 'jpg,jpeg,png,gif');// only JPEG, PNG, 
        
        
        $price = new Zend_Form_Element_Text('price');
        $price->setLabel('Giá')
             ->setRequired(true)
             ->addValidator('NotEmpty',true,array('messages' => 'Không được chống!'));
        $price->setAttrib('size', '70');
		
		$weight = new Zend_Form_Element_Text('weight');
        $weight->setLabel('Cân nặng')
             ->setRequired(true)
             ->addValidator('NotEmpty',true,array('messages' => 'Không được chống!'));
        $weight->setAttrib('size', '70');
        
        $madein = new Zend_Form_Element_Text('madein');
        $madein->setLabel('Xuất sứ');
            
        $madein->setAttrib('size', '70');
        
        $descriptions = new Zend_Form_Element_Textarea('description');
        $descriptions->setLabel('Mô Tả')
                 ->setRequired(true)
                 ->addValidator('NotEmpty',true,array('messages' => 'Không được trống!'));
        $descriptions->setAttrib('rows', '8');
        
        $descriptions_en = new Zend_Form_Element_Textarea('description_en');
        $descriptions_en->setLabel('Mô Tả English');
        $descriptions_en->setAttrib('rows', '8');
        
        $descriptions_china = new Zend_Form_Element_Textarea('description_china');
        $descriptions_china->setLabel('Mô Tả China');
        $descriptions_china->setAttrib('rows', '8');
        
        
        
        $content = new Zend_Form_Element_Textarea('content');
        $content->setLabel('Nội dung');
        $content->setAttrib('id','proContent');
        
        $content_en = new Zend_Form_Element_Textarea('content_en');
        $content_en->setLabel('Nội dung English');
        $content_en->setAttrib('id','proContentEn');
        
        $content_chi = new Zend_Form_Element_Textarea('content_china');
        $content_chi->setLabel('Nội dung China');
        $content_chi->setAttrib('id','proContentChi');
        
		
		$hot = new Zend_Form_Element_Checkbox('is_best');
        $hot->setLabel('Nổi bật');
		
		$is_sale = new Zend_Form_Element_Checkbox('is_sale');
        $is_sale->setLabel('Khuyến mại');
      
		
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Save');
        $submit->class = "bt-save";
        
        $this->addElements(array($category, $name, $image, $price, $madein, $weight, $descriptions, $content, $hot, $is_sale,
        $submit));                                           
    }  
}
